package com.wxhandle.cleandemo.api.exception;

public abstract class DomainException extends RuntimeException {
    
    public enum ErrorCode{
        // 业务错误定义
        DATA_VALID_FAIL(1,"请求的数据验证非法!"),
        REPEAT_REQUEST(2,"重复请求错误!"),
        NOT_FOUND(3, "未找到该资源!"), 
		OBJECT_NOT_NULL(4,"对象不可为空！"),
        INTERNAL_SERVER_ERROR(5, "IO错误!"),
        SERVER_BUSY(6,"服务器处理队列满，请稍后再试!"),
		DB_DATA_Integrity(7, "db数据关联错误！")
        ;

        /** 错误码 */
        private int code;
        /** 错误描述 */
        private String msg;

        ErrorCode(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }
        
    }
	private static final long serialVersionUID = 1L;

	/**
	 * 错误码
	 */
	protected ErrorCode code;
	/**
	 * 错误信息
	 */
	protected String msg;

	public DomainException(ErrorCode code, String msg) {
		super(code.getCode()+"");
		this.code = code;
		this.msg = code.getMsg();
	}
	
	

	public int getCode() {
		return code.getCode();
	}
	public String getCodeMsg() {
		return this.code.getMsg();
	}

	public String getMsg() {
		return this.msg;
	}

	@Override
	public Throwable fillInStackTrace() {
		return this;
	}
}
